package com.itsu.spbspider.service.impl;

import com.itsu.spbspider.entity.Crawler;
import com.itsu.spbspider.exception.SystemException;
import com.itsu.spbspider.mapper.CrawlerMapper;
import com.itsu.spbspider.service.CrawlerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class CrawlerServiceImpl implements CrawlerService {

    @Resource
    CrawlerMapper crawlerMapper;

    @Override
    public Crawler getCrawlerById(Integer id) throws SystemException {
        try {
            return crawlerMapper.selectById(id);
        } catch (Exception e) {
            throw new SystemException(e);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void updateCrawler(Crawler crawler) throws SystemException {
        try {
            crawlerMapper.updateById(crawler);
        } catch (Exception e) {
            throw new SystemException(e);
        }
    }
}
